export default function (res) {
    const { body } = res;

    const reqBodySchema = JSON.parse(
        '{"type":"object","required":["filters"],"properties":{"filters":{"description":"查询员工岗位参数","type":"object","$ref":"#/components/schemas/DeliverUserPositionQueryParam","required":["userId"],"properties":{"userId":{"type":"integer","description":"员工ID","format":"int64"}}},"start":{"type":"integer","description":"查询的第几页，默认从1开始","format":"int32"},"limit":{"type":"integer","description":"当前页查询的条数，默认每页10条","format":"int32"},"orderBy":{"type":"string","description":"排序字段"},"asc":{"type":"boolean","description":"排序方向,默认降序"}}}'
    );

    // 校验顶级必填参数
    if (reqBodySchema.required && reqBodySchema.required.length > 0) {
        for (const requiredField of reqBodySchema.required) {
            if (!body || !Object.prototype.hasOwnProperty.call(body, requiredField)) {
                return new Promise((resolve) => {
                    resolve({
                        code: 1,
                        message: `缺少必填参数：${requiredField}`,
                    });
                });
            }
        }
    }

    // 校验 filters 对象中的必填参数
    if (body && Object.prototype.hasOwnProperty.call(body, 'filters') && body.filters) {
        const filtersSchema = reqBodySchema.properties.filters;
        if (filtersSchema.required && filtersSchema.required.length > 0) {
            for (const requiredField of filtersSchema.required) {
                if (!Object.prototype.hasOwnProperty.call(body.filters, requiredField)) {
                    return new Promise((resolve) => {
                        resolve({
                            code: 1,
                            message: `filters中缺少必填参数：${requiredField}`,
                        });
                    });
                }
            }
        }
    }

    return new Promise((resolve) => {
        setTimeout(() => {
            const currentPage = body.start || 1;
            const pageSize = body.limit || 10;
            const totalItems = 30; // 假设总共有30条员工岗位数据
            const totalPages = Math.ceil(totalItems / pageSize);

            const positions = Array.from({ length: pageSize }, (_, index) => {
                const recordId = (currentPage - 1) * pageSize + index + 1;
                const startDate = new Date();
                startDate.setDate(startDate.getDate() - Math.floor(Math.random() * 365 * 2)); // 随机2年内的开始日期

                let endDate = null;
                const positionStatus = [1, 2][Math.floor(Math.random() * 2)]; // 1:在岗;2:已离岗
                if (positionStatus === 2) {
                    endDate = new Date(startDate.getTime() + Math.random() * 365 * 24 * 60 * 60 * 1000).toISOString().split('T')[0]; // 随机开始日期后1年内的离岗日期
                }

                return {
                    recordId: recordId,
                    org: {
                        id: [1, 2, 3, 4][Math.floor(Math.random() * 4)],
                        name: '组织' + Math.floor(Math.random() * 10),
                    },
                    position: {
                        id: [1, 2, 3, 4][Math.floor(Math.random() * 4)],
                        name: '岗位' + Math.floor(Math.random() * 5),
                    },
                    positionLevel: [103, 104, 105, 106][Math.floor(Math.random() * 4)], // 实习,初级,中级,高级,特级
                    positionStatus: positionStatus,
                    startDate: startDate.toISOString().split('T')[0], // 格式化为日期字符串
                    endDate: endDate,
                };
            });

            resolve({
                code: 0,
                message: 'success',
                data: {
                    current: currentPage,
                    size: pageSize,
                    total: totalItems,
                    list: positions,
                    summary: { // 汇总数据，可以根据实际业务逻辑填充
                        recordId: null,
                        org: { id: null, name: '总计' },
                        position: { id: null, name: '所有岗位' },
                        positionLevel: null,
                        positionStatus: null,
                        startDate: null,
                        endDate: null,
                    },
                },
                timestamp: Date.now(),
                signature: 'signature' + Math.floor(Math.random() * 1000),
                requestId: 'requestId' + Math.floor(Math.random() * 1000),
            });
        }, 100);
    });
}